{extend name="public:head"}
{block name="main"}

<form class="layui-form" action="/admin/Category/addOrUp" method="POST">


    <div class="layui-form-item">
        <label class="layui-form-label">分类名称</label>
        <div class="layui-input-inline" style="width:350px;">
            <input type="hidden" name="category_id" value="{$info['category_id']|default=''}">
            <input type="text" name="category_name" required lay-verify="required" placeholder="输入分类名称" autocomplete="off" class="layui-input"  value="{$info['category_name']|default=''}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">产品图片</label>
        <div class="layui-input-inline">
            <input type="text" id="img_upload_url" name="img_url" value="{$info['img_url']|default=''}"   placeholder="图片地址"  class="layui-input" lay-verify="required">
        </div>
        <div class="layui-input-inline" id="img_div" style="width: 50px;display: none">
            <img style="width: 37px;height: auto" type="hidden" id="img_upload" src="">
        </div>
        <div class="layui-input-inline">
            {notempty name="info['img_url']"}
            <img src="{$info['img_url']}" id="img_url" class="content-photos" style="height: 21px;">
            {/notempty}
            <a id="post_img" name="post_img" type="file" class="layui-btn layui-btn-small layui-btn-normal" data-name="thumb" style="margin-left:10px;">
                <i class="layui-icon">&#xe64a;</i>上传图片
            </a>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="switchTest" value="1" checked=''>
            <div class="layui-unselect layui-form-switch" lay-skin="_switch">
                <em>OFF</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="formDemo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<script type="text/javascript">


    layui.use(['form','layedit','upload'], function(){
        var form = layui.form
        var upload  = layui.upload;

        upload.render({
            elem: '#post_img'
            ,url: '/admin/Upload/upload_img' //必填项
            ,auto: true
            ,accept: 'file'
            ,method: 'post' //可选项。HTTP类型，默认post
            ,contentType: true    //不可缺
            ,processData: false
            // ,data: {} //可选项。额外的参数，如：{id: 123, abc: 'xxx'}
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
                $("#img_div").removeAttr('style');
                form.render();
            }
            ,done: function(res, index, upload){
                layer.closeAll('loading'); //关闭loading
                if(res.code == 200){
                    layer.msg('上传成功');
                    $("#img_upload_url").attr("value",res.path);
                    $("#img_upload").attr("type","");
                    $("#img_upload").attr("src",res.path);
                    $("#img_url").removeAttr("src");
                    form.render();
                }
                console.log(res);
            }
        });
    });

</script>

{/block}